<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 确定两个字符串是否接近 -->
    <script>
      var closeStrings = function (word1, word2) {
        if (word1.length != word2.length) return false
        let tab1 = new Array(26).fill(0)
        let tab2 = new Array(26).fill(0)
        for (let i = 0; i < word1.length; i++) {
          tab1[word1.charCodeAt(i) - 97]++
          tab2[word2.charCodeAt(i) - 97]++
        }
        for (let i = 0; i < 26; i++) {
          if (tab1[i] && tab2[i]) continue
          if (tab1[i] || tab2[i]) return false
        }
        tab1.sort((a, b) => a - b)
        tab2.sort((a, b) => a - b)
        for (let i = 0; i < 26; i++) {
          if (tab1[i] != tab2[i]) return false
        }
        return true
      }
      console.log(closeStrings('abc', 'bca'))
    </script>
  </body>
</html>
